// JavaScript Document

var readingelement;
var readid;
var currentshowpanel;

function read(id)
{
	readid = id;
	var showmessage = $('showmessage' + readid);
	if (showmessage == null)
	{
		var request  = new Ajax(); 
		request.get("message.aspx?action=read&id=" + id + "&timestamp=" + (new Date().getTime()), showresult);
	}
	else
	{
		if (showmessage.style.display == '')
		{ 
			showmessage.style.display = 'none';
		}
		else
		{
			currentshowpanel.style.display = 'none';
			showmessage.style.display = '';
		}
		currentshowpanel = showmessage;
	}
		 
}
function showresult(xmlobj)
{
	if (xmlobj.readyState == 4)
	{
		var response	= xmlobj.responseText;
		$("icon" + readid).src = $("icon" + readid).src.replace("unread.gif", "readed.gif");
		
		var obj = $('row' + readid);
		var table1 = obj.parentNode;
		var row1 = table1.insertRow(obj.rowIndex + 1);
		row1.id = 'showmessage' + readid;
		row1.className = 'forumtd';
		var cell = row1.insertCell(0); 
		cell.colSpan = obj.cells.length;
		cell.innerHTML = response;
		cell.className = 'bg2';
		if (currentshowpanel != null)
			currentshowpanel.style.display = 'none';
		currentshowpanel = row1; 
		
	}
}

function checknewmessage()
{
	var f = form('MessageForm');
	if (f.username)
	{
		if (f.username.value == '')
		{
			alert('请指定收件人！');
			f.username.focus();
			return false;
		}
		if (f.title.value == '')
		{
			alert('请指定消息标题！');
			f.title.focus();
			return false;
		}
		if (f.body.value == '')
		{
			alert('请指定消息内容！');
			f.body.focus();
			return false;
		}
		if (f.body.value.length > MessageSize)
		{
			alert('消息内容过长，当前只允许 '+ MessageSize + ' 个字符！');
			f.body.focus();
			return false;
		}
	}
	return true;
}